﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for EbookDetails
/// </summary>
public class EbookDetail
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string SubTitle { get; set; }
    public string Summary { get; set; }
    public string Edition { get; set; }
    public string Authors { get; set; }
    public int PublisherId { get; set; }
    public int PublishedYear { get; set; }
    public int CategoryId { get; set; }
    public string Link { get; set; }
    public int ThumbnailId { get; set; }
    public int CreatedBy { get; set; }
    public DateTime CreatedDate { get; set; }


    public EbookDetail()
    {
        //
        // TODO: Add constructor logic here
        //
        CreatedBy = 1;
    }

    public static List<EbookDetail> GetAllEBooks()
    {
        DBHelper dbhelper = new DBHelper();
        return dbhelper.GetAllEBooks();
    }

    public static EbookDetail GetEBooks(int EbookId)
    {
        DBHelper dbhelper = new DBHelper();
        List<EbookDetail> lstEbooks = dbhelper.GetAllEBooks();

        EbookDetail ebook = lstEbooks.Find(x => x.Id == EbookId);

        return ebook;
    }

    public void SaveEbookDetail(Byte[] btImage)
    {
        DBHelper dbhelper = new DBHelper();

        dbhelper.SaveEBookDetails(Id, Title, SubTitle, Summary, Edition, Authors,
            PublisherId, PublishedYear, CategoryId,
            Link, btImage, CreatedBy);
    }

    public byte[] GetThumbnail()
    {
        byte[] btImage;
        DBHelper dbhelper = new DBHelper();
        btImage = dbhelper.GetThumbnail(Id);

        return btImage;
    }
}